from Mode.Example import Example
from UI.addFundDiago import Ui_AddFundDialog
from PyQt5.QtWidgets import *
import sys
from PyQt5 import QtWidgets
from Mode.Log import Log
from Mode.SQLiteMode import SQLite
import Mode.GetFundProcess as fundFun

Tag = "AddFundDialog"

class AddFundDialog(QDialog, Ui_AddFundDialog):
    def __init__(self):
        super(AddFundDialog, self).__init__()
        self.setupUi(self)
        self.Cancel.clicked.connect(self.cancleCilck)
        self.OK.clicked.connect(self.oKClick)
        self.db = "Data.db"

    def oKClick(self):
        Log(Tag, "添加按钮：点击")
        fundCode = self.fundCode.text()
        positionPrice = self.positionPrice.text()
        positionNumber = self.positionNumber.text()
        if len(fundCode) != 6 or not fundCode.isdigit():
            QMessageBox.information(self,
                                    "提示",
                                    "请输入正确的基金代码~",
                                    QMessageBox.Ok)
            return
        Log(Tag,f"基金代码：{fundCode}\n"
                f"持仓价：{positionPrice}\n"
                f"持仓数：{positionNumber}")
        e = Example().andEqualTo("fund_id",fundCode)
        val = SQLite(self.db).select("fund_information",e)
        if len(val) != 0:
            QMessageBox.information(self,
                                    "提示",
                                    "盖基金已存在~",
                                    QMessageBox.Ok)
            return
        info = fundFun.GetFundJsonInfo(fundCode)





    def cancleCilck(self):
        Log(Tag,"取消按钮：点击")
        self.close()


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    win = AddFundDialog()
    win.show()
    sys.exit(app.exec_())